/*
 * strutils.c
 *
 *  Created on: 2013-5-14
 *      Author: xkaying
 */

#include "strutils.h"

#include <assert.h>

int StrOct(char *str)
{
	assert(str);
	int value;
	value=0;
	while((*str)!='\0'){
		value=value*8;
		value=value+(*str)-'0';
	}
	return value;
}

int StrHex(char *str)
{
	assert(str);
	int value;
	value=0;
	while((*str)!='\0'){
		value=value*16;
		if((*str)<='9'){
			value=value+(*str)-'0';
		}else if((*str)<='F'){
			value=value+(*str)-'A';
		}else{
			value=value+(*str)-'a';
		}
	}
	return value;
}

int StrDecimal(char *str)
{
	assert(str);
	int value;
	value=0;
	while((*str)!='\0'){
		value=value*10;
		value=value+(*str)-'0';
	}
	return value;
}
